<%@ page import="java.io.* , java.util.*, java.sql.*, com.myapp.struts.dao.*,com.myapp.struts.actionform.*,com.myapp.struts.beans.*"%>
<html xmlns="http://www.w3.org/1999/xhtml">
    <!-- DW6 -->
    <head>
        <!-- Copyright 2005 Macromedia, Inc. All rights reserved. -->
        <title>Item Master</title>
        <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
        <link href="../../../../css/cms.css" rel="stylesheet" type="text/css"> 

        <script language="javascript">
            function tabEvent(eve, ccount){
                var count = document.getElementById("optionCount").value;				
                var keynum;
                if(window.event) // IE
                    keynum = eve.keyCode;
                else if(eve.which) // Netscape/Firefox/Opera
                    keynum = eve.which;
                if(keynum == 9 && ccount == count){
                    count = parseInt(count) + 1;
                    document.getElementById("optionCount").value = count;
                    var appendStr = '<br><select name="achead" id="achead'+count+'"></select></label><input name="amt" type="text" id="amt'+count+'"/><label><input type="text" name="nar" id="nar'+count+'" onKeyDown="javascript:tabEvent(event, '+count+');"/></label>';
                    document.getElementById('rrows').innerHTML = document.getElementById('rrows').innerHTML + appendStr;
                    var eleIds = "achead"+count;
                    fillOptions(eleIds);
                }
            }

            function fillOptions(eleId)
            {
                var elemnt = document.getElementById(eleId);
                var actualEle = document.getElementById("achead");
                for(i=0;i<actualEle.length;i++){
                    addOption(elemnt,actualEle[i].text,actualEle[i].text);
                }
            }

            function addOption(selectbox,text,value )
            {
                var optn = document.createElement("OPTION");
                optn.text = text;
                optn.value = value;
                selectbox.options.add(optn);
            }
        </script>


        <script type="text/javascript">

            function getXMLObject()  //XML OBJECT
            {
                var xmlHttp = false;
                try {
                    xmlHttp = new ActiveXObject("Msxml2.XMLHTTP")  // For Old Microsoft Browsers
                }
                catch (e) {
                    try {
                        xmlHttp = new ActiveXObject("Microsoft.XMLHTTP")  // For Microsoft IE 6.0+
                    }
                    catch (e2) {
                        xmlHttp = false   // No Browser accepts the XMLHTTP Object then false
                    }
                }
                if (!xmlHttp && typeof XMLHttpRequest != 'undefined') {
                    xmlHttp = new XMLHttpRequest();        //For Mozilla, Opera Browsers
                }
                return xmlHttp;  // Mandatory Statement returning the ajax object created
            }

            var xmlhttp = new getXMLObject();	//xmlhttp holds the ajax object

            function getBalance() {
                var sel = document.getElementById("ptype");
                var opt = sel.options[sel.selectedIndex];
                var d = opt.value || opt.text;
                if(xmlhttp) {
                    xmlhttp.open("POST","../../../../AJAXAccountHeadBalance?head=" +d,true);
                    xmlhttp.onreadystatechange  = handleServerResponse;
                    xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
                    xmlhttp.send(null);
                }
            }

            function handleServerResponse() {
                if (xmlhttp.readyState == 4) {
                    if(xmlhttp.status == 200) {
                        var elemnt = document.getElementById("cashBalance");
                        var textToSplit = xmlhttp.responseText;
                        var returnElements=textToSplit.split("|");
                        var valueLabelPair=null;
                        valueLabelPair = returnElements[0].split("|");
                        document.getElementById('cashBalance').value = valueLabelPair[0];
                    }else {
                        alert("Error during AJAX call. Please try again");
                    }
                }
            }
        </script>
        <script type="text/javascript">

            var monthtext=[1,2,3,4,5,6,7,8,9,10,11,12];

            function populatedropdown(dayfield, monthfield, yearfield){
                var today=new Date()
                var dayfield=document.getElementById(dayfield)
                var monthfield=document.getElementById(monthfield)
                var yearfield=document.getElementById(yearfield)
                for (var i=0; i<31; i++)
                    dayfield.options[i]=new Option(i, i+1)
                dayfield.options[today.getDate()]=new Option(today.getDate(), today.getDate(), true, true) //select today's day
                for (var m=0; m<12; m++)
                    monthfield.options[m]=new Option(monthtext[m], monthtext[m])
                monthfield.options[today.getMonth()]=new Option(monthtext[today.getMonth()], monthtext[today.getMonth()], true, true) //select today's month
                var thisyear=today.getFullYear()
                for (var y=0; y<20; y++){
                    yearfield.options[y]=new Option(thisyear, thisyear)
                    thisyear+=1
                }
                yearfield.options[0]=new Option(today.getFullYear(), today.getFullYear(), true, true) //select today's year
            }

        </script>
    </head>
    <body>
        <div class="bodymain">
            <div class="pagedivide">
                <p>&nbsp;</p>
                <form name="Receipts" action="../../../../InsertPaymentEntry">
                    <table width="483" border="0" align="center" cellpadding="0" cellspacing="0" style="border-right: #000000 1px solid;
                           border-top: #000000 1px solid; border-left: #000000 1px solid;  border-bottom: #000000 1px solid; font-size: 9pt; color: #000000; font-family: Arial;" >
                        <tr>
                            <th height="31" colspan="6" align="center" valign="middle">Create Payments</th>
                        </tr>
                        <tr>
                            <td colspan="2"  class="tabledata">Payment  No</td>
                            <td colspan="2" ><label>
                                    <input name="pno" type="text" id="pno" />
                                </label></td>
                            <td width="84" align="center">Date </td>
                            <td width="163" align="center">
                                <select id="daydropdown" name="daydropdown">
                                    <option></option>
                                </select>
                                -

                                <select id="monthdropdown" name="monthdropdown">
                                    <option></option>
                                </select>
                                -
                                <select id="yeardropdown" name="yeardropdown">
                                    <option></option>
                                </select>

                                <script type="text/javascript">

                                    //populatedropdown(id_of_day_select, id_of_month_select, id_of_year_select)
                                    window.onload=function(){
                                        populatedropdown("daydropdown", "monthdropdown", "yeardropdown")
                                    }
                                </script>                    </td>
                        </tr>
                        <tr>
                            <td height="22" colspan="2" class="tabledata"> Payment Type</td>                            
                            <td height="22" colspan="2" class="tabledata"><select name="ptype" id="ptype"  onchange="javascript:getBalance()">
                                    <option>Select</option>
                                    <%
                  AcheadDao gadao = new AcheadDao();
                  ArrayList vvv1 = gadao.cashAndBankHeads();
                  if (vvv1 != null) {
                      Iterator it1 = vvv1.iterator();
                      while (it1.hasNext()) {
                          AccountHeadBean sb = (AccountHeadBean) it1.next();
                                    %>
                                    <option><%=sb.getAhead_Name()%></option>
                                    <%}
            }%>
                                </select></td>
                            <td><span class="tabledata">A/C  Balance</span></td>

                            <td colspan="2" align="center"><label><span class="tabledata">
                                        <input name='cashBalance' type='text' id='cashBalance'/>
                                    </span></label></td>
                        </tr>
                        <tr>
                            <th width="44" height="23" align="center" valign="middle" class="tabledata">&nbsp;</th>
                            <th height="23" colspan="2" align="center" valign="middle" class="tabledata">Account Head</th>
                            <th height="23" colspan="2" align="center" valign="middle" class="tabledata">Amount (Rs.)</th>
                            <th height="23" class="tabledata">Narration</th>
                        </tr>
                        <tr>
                            <td colspan="6" align="center" valign="middle" ><div id="rrows"><input type="hidden" name="optionCount" id="optionCount" value="0"><select name="achead" id="achead"><%AcheadDao ab = new AcheadDao();
            ArrayList vv = ab.getHeads();
            if (vv != null) {
                Iterator it = vv.iterator();
                while (it.hasNext()) {
                    AccountHeadBean sb = (AccountHeadBean) it.next();%><option><%=sb.getAhead_Name()%></option><%}
            }%></select></label><input name="amt" type="text" id="amt" onChange="writebox(this.form)"/><label><input type="text" name="nar" id="nar" onKeyDown="javascript:tabEvent(event, 0);"/></label></div></td>
                        </tr>


                        <tr>
                            <td height="24" colspan="6" align="center" valign="middle">
                                <input name="Submit" type="submit" class="tabledata" value="Submit" /></td>
                        </tr>
                    </table>
                </form>
            </div>
        </div>
    </body>
</html>
